package com.springclouddemo.service.user.config.localization;


import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component;

@Component
public class LocalUnity {
    private static MessageSource messageSource;

    public LocalUnity(MessageSource messageSource)
    {
        LocalUnity.messageSource = messageSource;
    }

    public static String get(String key)
    {
        try
        {
            return messageSource.getMessage(key, null, LocaleContextHolder.getLocale());
        }
        catch (Exception e)
        {
            return key;
        }
    }
}
